﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CatDb
{
    public partial class CatDetailsForm : Form
    {

        Cat _cat;

        private void fromCat() {
            _lb_id.Text = _cat.Id.ToString();
            _ed_name.Text = _cat.Name;
            _ed_description.Text = _cat.Description;
            _ed_gender.SelectedIndex = _cat.Gender == Gender.male ? 0 : 1;
            _ed_age.Value = _cat.Age;
            _cb_neutered.Checked = _cat.Neutered;
        }

        private void toCat() {
            _cat.Name = _ed_name.Text;
            _cat.Age = (int)_ed_age.Value;
            _cat.Gender = _ed_gender.SelectedIndex == 0 ? Gender.male : Gender.female;
            _cat.Description = _ed_description.Text;
            _cat.Neutered = _cb_neutered.Checked;
        }

        
        public CatDetailsForm(Cat cat) {
            InitializeComponent();
            _cat = cat;
        }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);
            fromCat();
        }

        private void _bn_ok_Click(object sender, EventArgs e) {
            toCat();
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }

        private void _bn_cancel_Click(object sender, EventArgs e) {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }

    
    }
}
